import { http } from "@/utils/http";

export type RequsetConfig = {
  data: object;
};
export const baseUrlApi = (url: string) => `/api/${url}`;

/** 基础响应类型 */
export type BaseRespon = {
  err: {
    code: number;
    msg: string;
  };
  status: {
    code: number;
    msg: string;
  };
};

/** 添加默认分页搜索参数 */
export function addPageConfig(config: RequsetConfig) {
  let defaultConfig: object = {
    page: 1,
    size: 10
  };

  let res = Object.assign({}, defaultConfig, config.data);
  return { data: res };
}

/** 获取图片上传token */
export const getUploadToken = (data: string) => {
  return http.request<any>("get", baseUrlApi(`index/storage/sign/${data}`));
};

/** 上传图片方法 */
export const uploadImage = (apiUrl, data) => {
  /** 上传图片请求配置 */
  const axiosConfig = {
    headers: {
      Accept: "*/*",
      "Content-Type": "image/png"
    }
  };
  return http.request<any>("put", apiUrl, { data }, axiosConfig);
};
